//获取应用实例
const app = getApp();
const request = app.request;
const setting = app.globalData.setting;
const bmap = require('../../../libs/bmap-wx.min.js');
const util = require('../../../utils/util.js');
const common = require('../../../utils/common.js');
const WxParse = require('../../../utils/wxParse/wxParse.js');
import LoadMore from '../../../utils/LoadMore.js';
const load = new LoadMore;
import Regions from '../../../utils/regions/Regions.js';
const auth = require('../../../utils/auth.js');

Page({
  data: {
    showCode: false,
    statusBar: app.globalData.statusBar,
    customBar: app.globalData.customBar,
    custom: app.globalData.custom,
    infologin: false,
    ak: 'vKWSosL5vUwrksmlYN0GKsKElHvcv3us', //百度地图key
    ad: true, //门店列表
    url: setting.url,
    indexnum: 0,
    resourceUrl: setting.resourceUrl,
    logo: setting.appLogo,
    appName: setting.appName,
    homeData: null, //首页轮播和广告
    saleGoods: null,
    teamActivityHome: null, //拼团列表
    defaultMenu: false, //默认底部菜单显示状态
    sale: {
      countTime: {
        hour: 0,
        minute: 0,
        second: 0,
      },
      diffTime: 0,
      good: null,
    },
    timer: null, //活动倒计时定时器
    recommend: [], //推荐商品
    scrollTop: 0,
    currentPage: 1,
    is_block: null,
    goods_show: 0,
    end_time: '', //秒杀结束时间
    countDownList: {
      day: '00',
      hou: '00',
      min: '00',
      sec: '00',
    }, //秒杀结束初始化时间
    webUrl: '',
    address: '', //当前地址
    menu_index: 0, //菜单索引
    custom_skill_status: false,
    from_address: {},
    goods: [],
    openSpecModal: false,
    goodsInputNum: 1, //选中的商品件数
    specSelect: 0, //选中的组合规格数组spec_goods_price下标
    optionItemId: 0, //页面参数，页面初始化指定显示的itemid，用于活动
    shippingCost: 0,
    hasSpec: true,
    select: { //选择的(规格)商品的参数，用于显示
      price: 0,
      stock: 0,
      specName: '',
      activity: null
    },
    pop_hidden: true,
    category: [],
    userInfo: app.globalData.userInfo,
    pickup_address: {},
    couponslist: [],
    couponslists: [],
    seckillCount: 0,

    // 是否下拉刷新
    isTriggered: false,
    // 轮播图
    images: [{
      url: '/images/index/banner.jpg',
      path: '/pages/goods/categoryList/categoryList'
    }],
    scrollTop: 0, // 滚动条位置
  },

  //事件处理函数
  onLoad: function (options) {
    let that = this;
    this.hidetabbar()
    console.log('onLoad-options:',options)
    console.log('onLoad-options:',decodeURIComponent(options.scene))
    var fl = decodeURIComponent(options.scene);
    var fls = fl.split('=');
    if (fls[0]=='first_leader') {
      wx.setStorageSync('first_leader', fls[1]);
    }
    console.log('onLoad-options:',fls)
    wx.setNavigationBarTitle({
      title: setting.appName,
    });
    //以前有登录过，则直接登录
    if (app.auth.hadAuth()) {
      app.getUserInfo();
    }
    let address2 = wx.getStorageSync('shop_select');
    if (address2) {
      that.setData({
        pickup_address: address2
      })
    }
    // this.miniapp_status();
    this.getcategory();
  },
  onShow: function (options) {
    let that = this;
    that.hidetabbar()
    that.setData({
      userInfo: app.globalData.userInfo
    });
    if (that.data.infologin) {
      that.data.infologin = false;
      that.checklogin();
    }
    that.getCardList()
    // setTimeout(function(){
    let address2 = wx.getStorageSync('shop_select');
    if (address2) {
      that.setData({
        pickup_address: address2
      })
    }
    // },1000)

    that.data.currentPage = 1
    that.data.recommend = []
    app.getConfig(function (res) {
      let is_block = common.getConfigByName(res.config, 'is_block_index');
      let wap_home_logo = common.getFullUrl(common.getConfigByName(res.config,
        'wap_home_logo')); //首页logo
      if (!app.globalData.config) {
        app.globalData.config = res.config
      }
      that.setData({
        is_block: is_block,
        wap_home_logo: wap_home_logo,
      });
      if (is_block == 0) {
        load.init(that, '', 'recommend');
        that.requestHomePage();
        that.requestRecommend();

        // that.requestTeamActivityHome();
        wx.removeStorageSync('custom_data');
        app.globalData.menu_model = [];
        that.setData({
          defaultMenu: true,
          menu_model: []
        });
        app.globalData.defaultMenu = true;
      } else {
        //预加载自定义缓存页面
        if (app.globalData.constom_index) {
          that.customRendering(app.globalData.constom_index);
        } else {
          wx.getStorage({
            key: 'custom_data',
            success(res) {
              if (typeof res.data == 'string') {
                res.data = JSON.parse(res.data);
              }
              that.customRendering(res.data);
            },
            fail() {

            }
          })
        }

        //第一次加载默认读取该页面自定义控件，有良好体验，通过点击菜单是一个跳转到自定义页面customPage        
        // that.checklogin();
        // that.getAutoData();
      }
    });
  },

  // 跳转
  handleCate: function (e) {
    let path = e.currentTarget.dataset.item
    wx.navigateTo({
      url: path
    })
  },

  // 加入购物车
  // addCart: function (e) {

  // 	console.log('加入购物车');
  // },

  // 下拉刷新
  onRefresherrefresh() {
    // this.setData({
    // 	isTriggered: true
    // })
    // this.data.recommend = [];
    // this.data.currentPage = 1;
    // this.requestRecommend()
  },

  // 触底刷新
  onScrolltolower() {
    // this.data.currentPage++
    // this.requestRecommend('more')
  },
  // requestCouponList() {
  // 	let that = this;
  // 	let requestUrl = '/api/activity/coupon_list?type=1&p=1';
  // 	request.get(requestUrl, {
  // 		success: function (res) {
  // 			let list = res.data
  // 			if (list.result.length > 0) {
  // 				for (var i in list.result) {
  // 					let val = list.result[i];
  // 					val.round = val.money.split(".")[0];
  // 					val.cond = val.condition.split(".")[0];
  // 					val.point = val.money.split(".")[1];
  // 					val.percent = val.createnum > 0 ? Math.ceil(val.send_num / val.createnum *
  // 						100) : 0;
  // 				}
  // 				that.setData({
  // 					couponslists: list.result
  // 				})
  // 			}
  // 		}
  // 	});
  // },
  getcategory() {
  	let that = this;
  	request.get('/api/goods/goodsCategoryList', {
  		isShowLoading: false,
  		data: {
  			new_ad: 1
  		},
  		success: function (res) {
  			let categories = res.data.result.category;
  			if (categories.length == 0) {
  				return;
  			}
  			that.setData({
  				category: categories
  			});
  		}
  	});
  },
  goTo(e) {
    let type = e.currentTarget.dataset.type;
    let id = e.currentTarget.dataset.path;
    switch (type) {
      case 3:
        wx.navigateTo({
          url: `/pages/goods/goodsInfo/goodsInfo?goods_id=${id}`,
        })
        break;
      case 4:
        app.globalData.cate_id = id
        wx.switchTab({
          url: '/pages/goods/categoryList/categoryList',
          success: function (e) {
            let page = getCurrentPages().pop();
            console.log('page:', page)
            if (page == undefined || page == null) return;
            page.onLoad();
            console.log(123)
          }
        })
        break;
      case 5:
        wx.navigateTo({
          url: id,
        })
        break;
      default:
        wx.navigateTo({
          url: id,
        })
        break;
    }
  },
  //是否在审核阶段
  // miniapp_status: function () {
  // 	let that = this;
  // 	//获取是不是在审核隐藏一些功能
  // 	request.get(that.data.url + '/api/app/mini_app', {
  // 		success: function (res) {
  // 			if (res.data.result.status == 1) {
  // 				app.globalData.is_apply = 1
  // 			}
  // 		}
  // 	});
  // },
  // 检查是否领取优惠券
  // check_coupon() {
  // 	let that = this;
  // 	let is_first = wx.getStorageSync('is_first');
  // 	if (is_first == 1) {
  // 		that.setData({
  // 			pop_hidden: true
  // 		})
  // 	} else {
  // 		that.setData({
  // 			pop_hidden: false
  // 		})
  // 	}
  // 	// var that = this;
  // 	// //检查用户是否登录方可操作立即购买
  // 	// if (!app.auth.isAuth()) {
  // 	//   that.setData({pop_hidden:false})
  // 	//   return;
  // 	// }
  // 	// request.get('/api/activity/check_coupon', {
  // 	//     data: { coupon_id: 2 },
  // 	//     success: function (res) {
  // 	//       if(res.data.is_chekc == 1){
  // 	//         that.setData({pop_hidden:true})
  // 	//       }else{
  // 	//         that.setData({pop_hidden:false})
  // 	//       }

  // 	//     }
  // 	// });
  // },
  // close: function () {
  // 	wx.setStorageSync('is_first', 1)
  // 	this.setData({
  // 		pop_hidden: true
  // 	})
  // },
  //领取优惠券
  // getCoupons() {
  // 	let that = this;
  // 	this.setData({
  // 		pop_hidden: true
  // 	})
  // 	//检查用户是否登录方可操作立即购买
  // 	if (!app.auth.isAuth()) {
  // 		wx.setStorageSync('coupon_login', true);
  // 		app.showLoading(null, 1500);
  // 		app.getUserInfo();
  // 		return;
  // 	}
  // 	request.post('/api/activity/get_coupon', {
  // 		data: {
  // 			coupon_id: 2
  // 		},
  // 		success: function (res) {
  // 			app.confirmBox(res.data.msg);
  // 			that.setData({
  // 				pop_hidden: true
  // 			})
  // 		}
  // 	});
  // },
  onPullDownRefresh: function (e) {
    // if (this.data.is_block == 0) {
    // 	this.data.recommend = null;
    // 	this.data.currentPage = 1;
    // 	load.resetConfig();
    // 	this.requestHomePage(); //首页数据
    // 	this.requestRecommend();
    // } else {
    // 	this.getAutoData();
    // 	wx.stopPullDownRefresh();
    // }
  },

  onReachBottom: function () {
    // if (this.data.is_block == 0 && load.canloadMore()) {
    // 	this.requestRecommend();
    // }
  },

  // 商品列表
  requestRecommend: function (type) {
    let that = this;
    let requestUrl = '/api/index/recommend?p=' + that.data.currentPage;
    load.request(requestUrl, function (res) {
      if (type == 'more') {
        let result = res.data.result || [];
        that.setData({
          recommend: [...that.data.recommend, ...result]
        })
      }
    }, () => {}, () => {
      that.setData({
        isTriggered: false
      })
    });
  },

  requestHomePage: function () {
    let that = this;
    request.get('/api/index/homePage?new_ad=1', {
      isShowLoading: false,
      success: function (res) {
        let banners = res.data.result.banner;
        for (var i = 0; i < banners.length; i++) {
          banners[i].ad_code = common.getFullUrl(banners[i].ad_code);
        }
        let ad = res.data.result.ad
        let ads = {}
        for (var i = 0; i < ad.length; i++) {
          ad[i].ad_link = that.parseAdUrl(ad[i].media_type, ad[i].ad_link);
          ad[i].ad_code = common.getFullUrl(ad[i].ad_code);
          ads['ad_' + ad[i].pid] = ad[i]
        }
        res.data.result.ad = ads
        let sale_goods = res.data.result.flash_sale_goods;
        if (sale_goods.length > 0) {
          that.setCountTime(res.data.result);
        } else {
          that.destroyActivityTimer();
        }
        if (sale_goods.length > 0 && sale_goods.length < 3) {
          that.setData({
            saleGoods: sale_goods
          });
        } else if (sale_goods.length >= 3) {
          let goods = [];
          for (var j = 0; j < 3; j++) {
            goods[j] = sale_goods[j];
          }
          that.setData({
            saleGoods: goods
          });
        }
        that.setData({
          homeData: res.data.result
        });
        console.log(res.data.result)
        wx.stopPullDownRefresh();
      }
    });
  },

  // 拼团列表
  // requestTeamActivityHome: function () {
  // 	let that = this;
  // 	request.get('/api/team/teamActivityHome', {
  // 		success: function (res) {
  // 			let res1 = res.data;
  // 			if (res1.status == 1) {
  // 				for (var i in res1.result) {
  // 					res1.result[i].team_price_new = res1.result[i].team_price.split('.');
  // 				}

  // 				that.setData({
  // 					teamActivityHome: res1.result
  // 				})
  // 			}

  // 		}
  // 	});
  // },
  // parseAdUrl: function (type, link) {
  // 	let $url
  // 	switch (type) {
  // 		case 3:
  // 			$url = '/pages/goods/goodsInfo/goodsInfo?goods_id=' + link
  // 			break;
  // 		case 4:
  // 			$url = '/pages/goods/goodsList/goodsList?id=' + link
  // 			break;
  // 		default:
  // 			$url = link
  // 			break;
  // 	}
  // 	return $url;
  // },

  // adTopage: function (e) {
  // 	let media_type = e.currentTarget.dataset.type;
  // 	let ad_link = e.currentTarget.dataset.link;
  // 	if (media_type == 3) {
  // 		if (ad_link != '') {
  // 			wx.navigateTo({
  // 				url: '/pages/goods/goodsInfo/goodsInfo?goods_id=' + ad_link
  // 			});
  // 		}
  // 	} else if (media_type == 4) {
  // 		if (ad_link != '') {
  // 			wx.navigateTo({
  // 				url: '/pages/goods/goodsList/goodsList?cat_id=' + ad_link
  // 			});
  // 		}
  // 	} else if (media_type == 5) {
  // 		if (ad_link != '') {
  // 			this.setData({
  // 				webUrl: ad_link
  // 			});
  // 			wx.navigateTo({
  // 				url: '/pages/index/webview/webview'
  // 			});
  // 		}
  // 	}
  // },
  // 页面分享相关事件处理函数
  onShareAppMessage() {
    return {
      title: '自定义分享标题',
      path: '/pages/index/index/index',
      imageUrl: '../../../images/share.png'
    }
  },
  onShareButtonClick() {
    wx.showShareMenu({
      withShareTicket: true // 是否使用带 shareTicket 的转发
    })
  },
  // buttfx() {
  // 	wx.showShareMenu({
  // 		withShareTicket: true // 是否使用带 shareTicket 的转发
  // 	})
  // },

  onUnload: function () {
    this.destroyActivityTimer();
  },

  // setCountTime: function (result) {
  // 	if (!result.diffTime) {
  // 		result.diffTime = (new Date()).getTime() - result.server_time * 1000;
  // 	}
  // 	let hour = util.format(result.server_time, 'h');
  // 	let flash_now_time = 0;
  // 	if (hour % 2 == 0) {
  // 		flash_now_time = hour;
  // 	} else {
  // 		flash_now_time = hour - 1;
  // 	}
  // 	if (hour.length == 1) {
  // 		flash_now_time = '0' + flash_now_time
  // 	}
  // 	this.setData({
  // 		flash_now_time: flash_now_time
  // 	});
  // 	this.setData({
  // 		'sale.diffTime': result.diffTime
  // 	});
  // 	this.setData({
  // 		'sale.good': result.flash_sale_goods[0]
  // 	});
  // 	this.destroyActivityTimer();
  // 	//this.createActivityTimer();
  // },

  /** 创建活动倒计时定时器 */
  // createActivityTimer: function () {
  // 	let sale = this.data.sale;
  // 	let that = this;
  // 	this.data.timer = setInterval(function () {
  // 		let time = sale.good.end_time * 1000 - (new Date()).getTime() + sale.diffTime;
  // 		let remainTime = util.transTime(time);
  // 		if (time <= 0) {
  // 			// that.destroyActivityTimer();
  // 			that.setData({
  // 				'sale.good': false
  // 			})
  // 			that.requestHomePage();
  // 			return;
  // 		}
  // 		that.setData({
  // 			'sale.countTime': remainTime
  // 		});
  // 	}, 1000);
  // },

  /** 销毁活动倒计时定时器 */
  destroyActivityTimer: function () {
    if (this.data.timer) {
      clearInterval(this.data.timer);
      this.data.timer = null;
    }
  },

  /** 页面滚动事件 */
  onPageScroll: function (e) {
    this.setData({
      scrollTop: e.scrollTop
    });
    //可能还在滚动就跳到其他页面去了，导致导航栏变色，所以要判断路由
    let pages = getCurrentPages();
    if (pages[pages.length - 1].route == 'pages/index/index/index') {
      if (e.scrollTop > 10) {
        wx.setNavigationBarColor({
          frontColor: '#000000',
          backgroundColor: '#ffffff'
        });
      } else {
        wx.setNavigationBarColor({
          frontColor: '#000000',
          backgroundColor: '#ffffff'
        });
      }
    }
  },

  jumpSearch: function () {
    wx.navigateTo({
      url: '/pages/goods/search/search'
    });
  },

  /**
   * 转发按钮
   */
  onShareAppMessage: function (res) {
    return setting.share;
  },

  getCardList: function (idx) {
    let that = this;
    request.get(that.data.url + '/api/cart/index?type=1', {
      isShowLoading: false,
      success: function (res) {
        that.setData({
          indexnum: res.data.result.user_cart_goods_type_num
        })
        if (idx || idx == 0) {
          for (let index = 0; index < res.data.result.cart_list.length; index++) {
            const element = res.data.result.cart_list[index];
            if (element.goods_id == that.data.recommend[idx].goods_id) {
              that.setData({
                ['recommend[' + idx + '].cart_id']: element.id
              });
              return;
            }
          }
        }
      }
    });
  },

  /** 减少购买的商品数量 */
  subCartNum: function (e) {
    this.checkCartNum(this.data.goodsInputNum - 1);
  },
  /** 增加购买的商品数量 */
  addCartNum: function (e) {
    this.checkCartNum(this.data.goodsInputNum + 1);
  },
  /** 输入购买的数量 */
  inputCartNum: function (e) {
    this.checkCartNum(Number(e.detail.value));
  },

  /** 检查购买的数量 */
  checkCartNum: function (num) {
    let specs = this.data.data.goods.spec_goods_price;
    let specSelect = this.data.specSelect;
    let activity = this.data.select.activity;
    let stock = this.data.data.goods.store_count;
    //参与活动
    if (activity && activity.activity_is_on == 1) {
      stock = activity.store_count
    } else {
      if (specs.length > 0) {
        stock = specs[specSelect].store_count;
      }
    }

    if (num > stock || stock == 0) {
      num = stock;
    } else if (num < 1) {
      num = 1;
    }
    this.setData({
      goodsInputNum: num
    });
  },
  /** 加入购物车 */
  addCart: function (e) {
    let that = this;
    let itemId = 0;
    let specs = this.data.data.goods.spec_goods_price;
    //区分有规格和无规格
    if (specs.length > 0) {
      if (specs[this.data.specSelect].store_count <= 0) {
        return app.showTextWarining("当前无库存！");
      }
      itemId = specs[this.data.specSelect].item_id;
    } else {
      if (this.data.data.goods.store_count <= 0) {
        return app.showTextWarining("当前无库存！");
      }
    }
    if (this.data.goodsInputNum <= 0) {
      return app.showTextWarining("商品数量不能小于1");
    }
    let data = {
      goods_id: this.data.data.goods.goods_id,
      goods_num: this.data.goodsInputNum,
      item_id: itemId,
      type: 1
    };
    if (this.data.data.goods.is_virtual) {
      return this.buyVirtualGoods(data);
    }
    if (e.currentTarget.dataset.action == 'add') { //加入购物车
      if (this.data.shippingCost < 0 || this.data.select.stock <= 0 || !this.data.hasSpec) {
        return;
      }
      request.post('/api/cart/add', {
        data: data,
        success: function (res) {
          that.setData({
            openSpecModal: false
          });
          request.checkUniqueId();
          app.showTextWarining('加入购物车成功');
          that.getCardList()
        }
      });
    } else if (e.currentTarget.dataset.action == 'exchange') { //立即兑换
      this.exchange(data);
    } else if (e.currentTarget.dataset.action == 'reserve') { //立即预订
      this.reserve(data);
    } else { //立即购买
      this.buyNow(data);
    }
  },
  /** 立即购买 */
  buyNow: function (data) {
    //检查用户是否登录方可操作立即购买
    if (!app.auth.isAuth()) {
      app.showLoading(null, 1500);
      app.getUserInfo();
      return;
    }
    if (this.data.shippingCost < 0 || this.data.select.stock <= 0 || !this.data.hasSpec) {
      return;
    }
    Object.assign(data, {
      action: 'buy_now',
    });
    this.setData({
      openSpecModal: false,
      enterAddressPage: true
    });
    wx.navigateTo({
      url: '/pages/cart/cart2/cart2?' + util.Obj2Str(data)
    });
  },
  /** 初始化数据，注意顺序 */
  initData: function (data) {
    //检查商品
    this.initCheckGoods(data);
    //检查一下购物的数量，可能无库存
    this.checkCartNum(this.data.goodsInputNum);
  },
  /** 检查商品 */
  initCheckGoods: function (data) {
    let that = this;
    request.post('/api/goods/activity', {
      data: {
        goods_id: data.goods.goods_id,
        item_id: data.goods.spec_goods_price.length > 0 ? data.goods.spec_goods_price[0][
          'item_id'
        ] : '',
      },
      success: function (res) {
        //初始化规格
        if (res.data.result.goods.activity_is_on == 1) {
          that.initSpecsPrice(res.data.result);
        } else {
          data.goods.prom_type = 0;
          that.initSpecsPrice(data);
        }
      }
    });
  },
  /** 初始化所有规格 */
  initSpecsPrice: function (data) {
    let specSelect = 0; //初始化选中第一个规格 
    let specs = this.data.data.goods.spec_goods_price;
    if (specs.length == 0) {
      //没有规格
      this.initActivity(data.goods);
      return;
    }
    //第一次请求的总数据中的activity默认是第一种规格的,可减少一次请求
    //specs[0].activity = data.goods;
    // if (this.data.optionItemId) { //指定规格
    //     for (var i = 0; i < specs.length; i++) {
    //         if (specs[i].item_id == this.data.optionItemId) {
    //             specSelect = i;
    //             break;
    //         }
    //     }
    // } else { //初始化选库存不为0的规格
    //     for (var i = 0; i < specs.length; i++) {
    //         if (specs[i].store_count <= 0) {
    //             continue;
    //         }
    //         specSelect = i;
    //         break;
    //     }
    // }
    // specs[specSelect].activity = data.goods;
    //生成子规格组(goods_spec_list)的各自选中项
    let specIds = specs[specSelect].key.split("_");
    let list = this.data.data.goods.spec;

    this.initSelectSpecGoods();
  },
  /** 初始化选中的规格商品 */
  initSelectSpecGoods: function () {
    let specSelect = this.data.specSelect;
    let specs = this.data.data.goods.spec_goods_price;
    let itemId = specs[specSelect].item_id;
    if (specs[specSelect].prom_type == 0) {
      let noActivity = {
        prom_type: 0
      };
      specs[specSelect].activity = noActivity;
      this.initActivity(noActivity);
    } else if (typeof specs[specSelect].activity != 'undefined') {
      this.initActivity(specs[specSelect].activity);
    } else {
      this.requestSpecInfo(specSelect);
    }
  },
  /** 点击规格按钮的回调函数 */
  selectSpec: function (e) {
    //对商品数量进行判断，对库存进行判断
    let itemId = e.currentTarget.dataset.itemid;
    let listIdx = e.currentTarget.dataset.listidx;
    let list = this.data.data.goods_spec_list;
    if (list[listIdx].selectItemId == itemId) {
      return;
    }
    list[listIdx].selectItemId = itemId;
    let newSpecKeys = [];
    for (var i = 0; i < list.length; i++) {
      newSpecKeys[i] = list[i].selectItemId;
    }
    //item排序,生成key
    newSpecKeys = util.sortSize(newSpecKeys).join('_');
    let newSpecSelect = 0;
    let specs = this.data.data.goods.spec_goods_price;
    let hasSpec = false;
    for (var i = 0; i < specs.length; i++) {
      if (specs[i].key == newSpecKeys) {
        hasSpec = true;
        newSpecSelect = i;
        break;
      }
    }
    this.setData({
      hasSpec: hasSpec,
      specSelect: newSpecSelect,
      'data.goods_spec_list': list,
      isBragain: this.data.isSeparate ? false : true,
    });
    this.initSelectSpecGoods();
    this.checkCartNum(this.data.goodsInputNum);
  },
  /** 初始化显示的活动信息 */
  initActivity: function (activity) {
    // if (activity.prom_type && activity.prom_type != 6) {
    // 	let startTime = (new Date()).getTime();
    // 	if (activity.prom_type == 1) { //抢购
    // 		activity.priceName = '抢购价';
    // 		activity.countName = '限时抢购';
    // 	} else if (activity.prom_type == 2) { //团购
    // 		activity.priceName = '团购价';
    // 		activity.countName = '限时团购';
    // 	} else if (activity.prom_type == 3) { //促销
    // 		activity.countName = '优惠促销';
    // 	} else if (activity.prom_type == 4) { //预售
    // 		activity.priceName = '预售价';
    // 		activity.countName = '预售商品';
    // 	} else if (activity.prom_type == 8) { //砍价
    // 		!this.data.isBragain ? activity.priceName = '砍价享' : activity.priceName = ''!this.data
    // 			.isBragain ? activity.countName = '砍价活动' : activity.countName = ''
    // 	}

    // 	activity.countTime = '--天--时--分--秒';
    // 	if (!activity.diffTime) {
    // 		activity.diffTime = (new Date()).getTime() - activity.server_current_time * 1000;
    // 	}
    // } else if (activity.prom_type == 6) {
    // 	activity.countName = '该商品正在参与拼团';
    // 	activity.goods_id = activity.goods_id;
    // 	activity.team_id = activity.prom_id ? activity.prom_id : 0;
    // 	activity.item_id = activity.item_id ? activity.item_id : 0;
    // }
    // this.setData({
    // 	'select.activity': activity
    // });
    // this.destroyActivityTimer();
    // this.initSelectedData();
  },

  /** 初始化选中的（规格）商品的显示参数 */
  initSelectedData: function () {
    let goods = this.data.data.goods;
    let activity = this.data.select.activity;
    let specs = this.data.data.goods.spec_goods_price;
    let specSelect = this.data.specSelect;
    let stock = 0;
    let price = 0;
    if (activity.prom_type == 1 || activity.prom_type == 2) {
      price = activity.shop_price;
      stock = activity.store_count;
    } else if (activity.prom_type == 3) {
      price = activity.shop_price;
      // stock = specs.length > 0 ? specs[specSelect].store_count : goods.store_count;
      stock = activity.store_count;
    } else if (activity.prom_type == 4) {
      price = activity.shop_price;
      //stock = specs.length > 0 ? specs[specSelect].store_count : goods.store_count;
      stock = activity.store_count;
    } else if (activity.prom_type == 8 && !this.data.isBragain) {
      price = activity.end_price ? activity.end_price : activity.shop_price;
      stock = activity.store_count;
      this.setData({
        'select.bargain_price': price,
      });
    } else if (specs.length > 0) {
      price = specs[specSelect].price;
      stock = specs[specSelect].store_count;
    } else {
      price = goods.shop_price;
      stock = goods.store_count;
    }
    this.setData({
      'select.price': price,
      'select.stock': stock,
      'select.specName': specs.length > 0 ? specs[specSelect].key_name : '',
    });
    if (this.data.isBragain) {
      this.setData({
        isBragain: false
      })
    }
  },
  addNum: function (e) {
    let that = this;
    //在个人中心浏览其他入口页面前判断是否登录
    if (!that.data.userInfo) {
      app.getUserInfo(function (userInfo) {
        that.setData({
          userInfo: userInfo,
          click: false
        });
      }, true, false);
      return false;
    }
    let index = e.currentTarget.dataset.item
    let cart = that.data.recommend[index];
    let data = {
      goods_id: cart.goods_id,
      goods_num: 1,
      item_id: 0,
      type: 1
    }
    request.post('/api/cart/add', {
      data: data,
      isShowLoading: false,
      success: function (res) {
        if (res.data.status == 1) {
          cart.cart_num++;
          that.setData({
            ['recommend[' + index + '].cart_num']: cart.cart_num,
            // ['recommend[' + index + '].cart_id']: res.data.cart_id
          });
          app.showTextWarining('加入购物车成功');
          // 更新购物车角标数量
          that.getCardList(index);
        }
      }
    })
  },

  subNum(e) {
    let that = this;
    //在个人中心浏览其他入口页面前判断是否登录
    if (!that.data.userInfo) {
      app.getUserInfo(function (userInfo) {
        that.setData({
          userInfo: userInfo,
          click: false
        });
      }, true, false);
      return false;
    }
    let index = e.currentTarget.dataset.item
    let cart = this.data.recommend[index]
    let data = {
      'cart[id]': cart.cart_id,
      'cart[goods_num]': cart.cart_num - 1,
      type: 1
    }
    request.post(that.data.url + '/api/cart/changeNum', {
      data: data,
      isShowLoading: false,
      success: function (res) {
        if (res.data.status == 1) {
          that.setData({
            ['recommend[' + index + '].cart_num']: cart.cart_num - 1
          });

          // 更新购物车角标数量
          that.getCardList();
        }

      }
    });


  },

  /** 关闭规格弹窗 */
  closeSpecModal: function () {
    this.setData({
      openSpecModal: false
    });
  },
  /** 打开规格弹窗 */
  openSpecModel: function (e) {
    let that = this;
    request.get('/api/goods/goodsInfo', {
      data: {
        id: e.currentTarget.dataset.goods_id
      },
      failRollback: true,
      success: function (res) {
        that.setData({
          data: res.data.result,
          openSpecModal: true
        });
        that.initData(res.data.result);
      }
    });
  },
  /****************************** 自定义 start ********************************/
  getAutoData: function (id) {
    let that = this;
    let url = !id ? '/api/Index/block_index' : '/api/Index/block_index/id/' + id
    request.get(url, {
      failRollback: true,
      successReload: true,
      isShowLoading: false,
      success: function (res) {
        if (res.data.status == 1) {
          //真机上该存储方式超出最大内存限制
          //wx.setStorageSync('custom_data', JSON.stringify(res.data.result.blocks))

          wx.setStorage({
            key: "custom_data",
            data: res.data.result.blocks
          })
          app.globalData.constom_index = res.data.result.blocks;
          that.customRendering(res.data.result.blocks)
        }

      }
    });
  },
  customRendering: function (custom) {
    let that = this;
    let data = custom; //模块集合
    let skill = []; //秒杀
    let block_model = []; //其他模块集合
    let shop = []; //多门店集合
    let content = []; //富文本集合
    let menu_model = []; //菜单集合
    let video = []; //视频集合
    let search = []; //搜索
    let ids = [];

    for (let z = 0; z < data.length; z++) {
      if (data[z]['block_type'] == '6') {
        skill = data[z];
      }

      if (data[z]['block_type'] == '14') {
        data[z]['video_url'] = data[z]['video_url'].indexOf('http') == -1 ? setting.url + data[z][
          'video_url'
        ] : data[z]['video_url'];
        video = data[z];
      }

      if (data[z]['block_type'] != '8' && data[z]['block_type'] != '9' && data[z]['block_type'] !=
        '11') {

        if (data[z]['block_type'] == '3') {
          data[z]['list'] = data[z]['nav'][0]['goods_list']
        }

        block_model.push(data[z]);
        ids.push(data[z]['div_order'])
      }
      if (data[z]['block_type'] == '8') {
        search = data[z];
      }

      if (data[z]['block_type'] == '18') {
        shop = data[z];
      }

      if (data[z]['block_type'] == '16') {
        content = data[z];
      }

      if (data[z]['block_type'] == '11') {
        menu_model = data[z];
      }

      if (data[z]['block_type'] == '19') {
        for (let i = 0; i < data[z]['nav'].length; i++) {
          if (data[z]['nav'][i]['type'] == 4) {
            //radio_from = data[z]['nav'][i]['option_name'];
            let len = data[z]['nav'][i]['option_name'].length;
            let arrs = [];
            for (let ii = 0; ii < len; ii++) {
              let obj = {
                name: data[z]['nav'][i]['option_name'][ii],
                selected: -1
              }
              arrs.push(obj)
            }
            data[z]['nav'][i]['option_name'] = arrs
          }

          if (data[z]['nav'][i]['type'] == 5) {
            //checked_from = data[z]['nav'][i]['option_name'];
            let len = data[z]['nav'][i]['option_name'].length;
            let arrs = [];
            for (let ii = 0; ii < len; ii++) {
              let obj = {
                name: data[z]['nav'][i]['option_name'][ii],
                selected: -1
              }
              arrs.push(obj)
            }
            data[z]['nav'][i]['option_name'] = arrs
          }
        }
        that.initRegions();
      }
    }

    let array = [];
    if (ids.length > 0) {
      for (let y = 1; y <= ids.length; y++) {
        array.push(y);
      }
    }

    if (content != '') {
      WxParse.wxParse('content', 'html', content.content, that, 6);
    }

    if (skill != '' && skill.activity_type == 1) {
      that.setData({
        end_time: skill.end_time
      })
      that.destroyActivityTimer();
      that.data.timer = setInterval(function () {
        that.secondKill();
      }, 1000);

    }

    if (shop != '') {
      wx.getLocation({
        type: 'wgs84',
        altitude: true,
        success: function (res) {
          that.getUserLatitudeLongitude(shop, res);

        },
        fail(e) {
          app.confirmBox('如需正常使用小程序门店自提点功能，请在【我的】页面中点击授权按钮，勾选用户信息并点击确定。');
        }
      })
    }
    block_model = that.returnModelArr(block_model, array);
    app.globalData.menu_model = menu_model.nav;
    that.setData({
      video: video,
      search: search,
      menu_model: menu_model.nav,
      models: data,
      block_model: block_model
    });
  },

  /** 获取授权用户经纬度 */
  getUserLatitudeLongitude(result, res) {
    let that = this;
    //根据用户当前经纬度获取相应的附近门店
    request.post('/api/Index/shopList', {
      data: {
        lng: res.longitude,
        lat: res.latitude,
        province: '',
        search_radius: result.search_radius,
      },
      failRollback: true,
      successReload: true,
      isShowLoading: false,
      success: function (res) {
        let ad = res.data.result.length > 0 ? false : true;
        that.setData({
          shop_list: res.data.result,
          ad: ad
        })
      }
    });

    //用户当前经纬度地址位置
    let BMap = new bmap.BMapWX({
      ak: that.data.ak,
    });
    let fail = function (data) {};
    let success = function (data) {
      let originalData = data.originalData;
      that.setData({
        address: originalData.result.formatted_address
      })
    }
    BMap.regeocoding({
      location: res.latitude + ',' + res
        .longitude, //22.622572 + ',' + 114.077780, // 22.71991 + ',' + 114.24779, 
      fail: fail,
      success: success,
    });
  },
  shop_page(e) {
    wx.navigateTo({
      url: '/pages/cart/cart2/shopDetail/shopDetail?datas=' + JSON.stringify(e.currentTarget
        .dataset.item)
    });
  },
  /** 自定义模板秒杀接口时间数据 */
  secondKill: function () {
    // 获取当前时间
    let newTime = new Date().getTime();
    let countDownArr = null;
    // 对结束时间进行处理渲染到页面    
    let endTime = this.data.end_time * 1000; //活动结束时间       
    let obj = null;
    // 如果活动未结束，对时间进行处理
    if (endTime - newTime > 0) {
      let time = (endTime - newTime) / 1000;
      // 获取天、时、分、秒
      let day = parseInt(time / (60 * 60 * 24));
      let hou = parseInt(time % (60 * 60 * 24) / 3600);
      let min = parseInt(time % (60 * 60 * 24) % 3600 / 60);
      let sec = parseInt(time % (60 * 60 * 24) % 3600 % 60);
      obj = {
        day: this.timeFormat(day),
        hou: this.timeFormat(hou),
        min: this.timeFormat(min),
        sec: this.timeFormat(sec)
      }
    } else { //活动已结束，全部设置为'00'
      //if (time <= 0) {
      this.destroyActivityTimer();
      this.setData({
        custom_skill_status: false
      })
      this.getAutoData(); //首页数据
      return;
      // }
    }
    countDownArr = obj;
    this.setData({
      countDownList: countDownArr,
      custom_skill_status: true
    });
  },

  timeFormat(param) { //小于10的格式化函数
    return param < 10 ? '0' + param : param;
  },


  /** 领券 */
  getCoupon: function (e) {
    let that = this;
    let coupon_id = e.currentTarget.dataset.cid;
    request.post('/api/activity/get_coupon', {
      data: {
        coupon_id: coupon_id
      },
      success: function (res) {
        app.showSuccess(res.data.msg);
        for (var i in that.data.coupons) {
          if (that.data.coupons[i].id == coupon_id) {
            that.data.coupons.splice(i, 1);
            that.setData({
              coupons: that.data.coupons
            });
            break;
          }
        }
      }
    });
  },
  login: function () {
    let that = this;
    if (that.data.click) return false;
    that.data.click = true;
    if (!that.data.userInfo.user_id) {
      app.getUserInfo(function (userInfo) {
        that.data.click = false;
        that.setData({
          userInfo: userInfo
        });
      }, true, false);

    } else {
      that.data.click = false;
    }
  },
  clickMenu(e) {
    let that = this;
    // if (that.data.click) return false;
    // that.data.click = true;
    //在个人中心浏览其他入口页面前判断是否登录
    if (!that.data.userInfo) {
      app.getUserInfo(function (userInfo) {
        that.setData({
          userInfo: userInfo,
          click: false
        });
      }, true, false);
      return false;
    }
    if (e.currentTarget.dataset.url == '/pages/distribut/index/index') {
      if (that.data.distribut == 0) {
        // that.data.click = false;
        return app.showTextWarining('分销功能已关闭')
      }
    }
    if (e.currentTarget.dataset.url == '/pages/user/sign_in/sign_in') {
      if (that.data.sign == 0) {
        // that.data.click = false;
        return app.showTextWarining('签到功能已关闭')
      }
    }
    if (e.currentTarget.dataset.url == 'webview') {
      this.setData({
        webUrl: "/Mobile/User/userHelpList/app/3"
      });
      wx.navigateTo({
        url: '/pages/index/webview/webview'
      });
      return false;
    }

    wx.navigateTo({
      url: e.currentTarget.dataset.url
    });
  },
  /** 跳转模式 自定义页面 || 自定义菜单 || 自定义控件控件*/
  topage: function (e) {
    //自定义控件控件
    let obj = e.currentTarget.dataset.obj ? e.currentTarget.dataset.obj : '';
    let url = e.currentTarget.dataset.url;
    let page_type = e.currentTarget.dataset.type;
    let id = e.currentTarget.dataset.id;
    if (obj == 'custom') {
      //底部自定义菜单
      let idx = e.currentTarget.dataset.idx;
      app.globalData.menu_index = idx;
      page_type = this.data.menu_model[idx].url_type
      id = this.data.menu_model[idx].app_url
    }
    //判断跳转的类型  1 = 小程序页面，2 = 分类商品，3 = 商品详情 ，4 = 自定义页面 , 5 = 外部网址链接,
    if (page_type == 1) {
      if (obj == 'custom') {
        //要访问的页面idx，当前页面menu_index
        common.totabar(idx, this.data.menu_index, this.data.menu_model);
      } else {
        let url = common.meunCheck(e.currentTarget.dataset.url);

        if (url.tab == 1) {
          wx.switchTab({
            url: url.url,
          });

        } else {
          wx.navigateTo({
            url: url.url,
          });

        }
      }

    } else if (page_type == 2) {
      wx.navigateTo({
        url: '/pages/goods/goodsList/goodsList?cat_id=' + id
      });
    } else if (page_type == 3) {
      wx.navigateTo({
        url: '/pages/goods/goodsInfo/goodsInfo?goods_id=' + id
      });
    } else if (page_type == 5 || page_type == 0) {
      if (url == "") {
        return false;
      }
      this.setData({
        webUrl: url ? url : id
      });
      wx.navigateTo({
        url: '/pages/index/webview/webview'
      });
    } else {
      //自定义页面      
      if (obj == 'custom') {
        wx.reLaunch({
          url: '../../index/customPage/customPage?id=' + this.data.menu_model[idx]
            .app_url,
        })
      } else {
        wx.navigateTo({
          url: '../../index/customPage/customPage?id=' + id + '&types=-1',
        })
      }

    }
  },
  /** 默认菜单 */
  topages: function (e) {
    let idx = e.currentTarget.dataset.idx;
    app.globalData.menu_index = idx;
    console.log(idx)
    if (idx == 4) {
      if (!app.auth.isAuth()) {
        app.showLoading(null, 1500);
        app.getUserInfo();
        return;
      }
      if(this.data.userInfo.xcx_qrcode) {
        this.showCode();
      } else {
        app.showTextWarining('请先加入会员')
      }
    } else {
      this.setData({
        showCode: false
      })
      common.defaultTotabar(idx, 0);
    }
  },

  showCode() {
    this.setData({
      showCode: !this.data.showCode
    })
  },

  //新闻详情
  goNewsDetail: function (e) {
    let id = e.currentTarget.dataset.id;
    let link = e.currentTarget.dataset.link;
    if (id != '') {
      wx.navigateTo({
        url: '/pages/news/news_detail/news_detail?article_id=' + id
      });
    } else {
      wx.navigateTo({
        url: '/pages/news/news_list/news_list'
      });
    }
  },

  changeGoodsShow(e) {
    let index = e.currentTarget.dataset.index;
    let fid = e.currentTarget.dataset.fid;
    this.data.block_model[fid]['list'] = this.data.block_model[fid]['nav'][index]['goods_list']
    this.data.block_model[fid]['title_selected'] = index
    this.setData({
      goods_show: index,
      goods_show_fid: fid,
      block_model: this.data.block_model
    });
  },

  returnModelArr: function (data, ids) {
    let arr = [];
    for (let i = 0; i < ids.length; i++) {
      for (let l = 0; l < data.length; l++) {
        if (ids[i] == data[l]['div_order']) {
          arr.push(data[l]);
        }
      }
    }
    return arr;
  },
  tologin: function () {
    if (!app.auth.isAuth()) {
      app.showLoading(null, 1500);
      app.getUserInfo();
      this.data.infologin = true;
    }
  },
  checklogin: function () {
    this.setData({
      iflogin: app.auth.hadAuth()
    })
  },
  bindTimeChange(e) {
    let that = this;
    let fid = e.currentTarget.dataset.fid;
    let idx = e.currentTarget.dataset.idx;
    let datas = that.data.block_model;
    datas[fid]['nav'][idx]['val'] = e.detail.value
    this.setData({
      intelligence_date: e.detail.value,
      block_model: datas
    });
  },
  /** 初始化区域弹框相关 */
  initRegions: function (e) {
    let that = this;
    new Regions(this, 'regions', {
      endAreaLevelCall: function (parentId, regionName, address) {
        Object.assign(that.data.from_address, address);
        that.setData({
          'from_address.province_name': that.data.from_address.province_name,
          'from_address.city_name': that.data.from_address.city_name,
          'from_address.district_name': that.data.from_address.district_name,
          'from_address.twon_name': that.data.from_address.twon_name,
        });
      },
      setFromRegionsVal: function (selected, address) {
        let fid = selected.fid;
        let idx = selected.idx;
        let datas = that.data.block_model;

        datas[fid]['nav'][idx]['val'] = address.province_name + address.city_name +
          address.district_name + address.twon_name
        that.setData({
          block_model: datas
        })
      }
    });
  },

  // radioChange: function (e) {
  // 	let that = this;
  // 	let fid = e.currentTarget.dataset.fid;
  // 	let idx = e.currentTarget.dataset.idx;
  // 	let idxs = e.currentTarget.dataset.idxs;
  // 	let datas = that.data.block_model;
  // 	for (let i = 0; i < datas[fid]['nav'][idx]['option_name'].length; i++) {
  // 		datas[fid]['nav'][idx]['option_name'][i]['selected'] = -1
  // 		datas[fid]['nav'][idx]['val'] = ''
  // 	}
  // 	datas[fid]['nav'][idx]['option_name'][idxs]['selected'] = idxs
  // 	datas[fid]['nav'][idx]['val'] = datas[fid]['nav'][idx]['option_name'][idxs]['name']
  // 	that.setData({
  // 		block_model: datas
  // 	})

  // },
  // checkboxChange: function (e) {
  // 	let that = this;
  // 	let fid = e.currentTarget.dataset.fid;
  // 	let idx = e.currentTarget.dataset.idx;
  // 	let idxs = e.currentTarget.dataset.idxs;
  // 	let datas = that.data.block_model;

  // 	if (datas[fid]['nav'][idx]['option_name'][idxs]['selected'] == idxs) {
  // 		datas[fid]['nav'][idx]['option_name'][idxs]['selected'] = -1
  // 	} else {
  // 		datas[fid]['nav'][idx]['option_name'][idxs]['selected'] = idxs
  // 	}
  // 	let val = '';
  // 	if (datas[fid]['nav'][idx]['option_name'].length > 0) {
  // 		for (let i = 0; i < datas[fid]['nav'][idx]['option_name'].length; i++) {
  // 			if (datas[fid]['nav'][idx]['option_name'][i]['selected'] >= 0) {
  // 				if (val) {
  // 					val += ',' + datas[fid]['nav'][idx]['option_name'][i]['name']
  // 				} else {
  // 					val += datas[fid]['nav'][idx]['option_name'][i]['name']
  // 				}
  // 			}
  // 		}
  // 	}
  // 	datas[fid]['nav'][idx]['val'] = val;
  // 	that.setData({
  // 		block_model: datas
  // 	})
  // },
  // checkFromType: function (e) {
  // 	let that = this;
  // 	let fid = e.currentTarget.dataset.fid;
  // 	let idx = e.currentTarget.dataset.idx;
  // 	let datas = that.data.block_model;
  // 	datas[fid]['nav'][idx]['val'] = e.detail.value;
  // 	that.setData({
  // 		block_model: datas
  // 	})
  // },
  // fromSubmit: function (e) {

  // 	let that = this;
  // 	let datas = that.data.block_model;
  // 	let fid = e.currentTarget.dataset.fid;
  // 	let data = '';
  // 	for (let j = 0; j < datas[fid]['nav'].length; j++) {
  // 		if (datas[fid]['nav'][j]['required'] == 1 && !datas[fid]['nav'][j]['val'] && (datas[fid]['nav'][
  // 			j
  // 		]['type'] == 0 || datas[fid]['nav'][j]['type'] == 1)) {
  // 			return app.showTextWarining("请填写" + datas[fid]['nav'][j]['title']);
  // 		}

  // 		if (datas[fid]['nav'][j]['type'] == 0 && datas[fid]['nav'][j]['verify_type'] == 1) {
  // 			if (!app.validatemobile(datas[fid]['nav'][j]['val'])) {
  // 				return;
  // 			}
  // 		}

  // 		if (datas[fid]['nav'][j]['type'] == 0 && datas[fid]['nav'][j]['verify_type'] == 2) {
  // 			if (!common.checkEmail(datas[fid]['nav'][j]['val'])) {
  // 				return app.showTextWarining("请填写" + datas[fid]['nav'][j]['title'] + '正确的格式');
  // 			}
  // 		}

  // 		if (datas[fid]['nav'][j]['required'] == 1 && !datas[fid]['nav'][j]['val'] && (datas[fid]['nav'][
  // 			j
  // 		]['type'] == 2 || datas[fid]['nav'][j]['type'] == 3 || datas[fid]['nav'][j]['type'] ==
  // 			5 || datas[fid]['nav'][j]['type'] == 4)) {
  // 			return app.showTextWarining("请选择" + datas[fid]['nav'][j]['title']);
  // 		}
  // 		let text = datas[fid]['nav'][j]['val'] ? datas[fid]['nav'][j]['val'] : '';
  // 		data += '&name' + j + '=' + text
  // 	}

  // 	//验证之后清空数据
  // 	for (let i = 0; i < datas[fid]['nav'].length; i++) {
  // 		datas[fid]['nav'][i]['val'] = '';
  // 		if (datas[fid]['nav'][i]['type'] == 4) {
  // 			for (let y = 0; y < datas[fid]['nav'][i]['option_name'].length; y++) {
  // 				datas[fid]['nav'][i]['option_name'][y]['selected'] = -1;
  // 			}
  // 		}

  // 		if (datas[fid]['nav'][i]['type'] == 5) {
  // 			for (let u = 0; u < datas[fid]['nav'][i]['option_name'].length; u++) {
  // 				datas[fid]['nav'][i]['option_name'][u]['selected'] = -1;
  // 			}
  // 		}
  // 	}

  // 	let from_datas = '?timeid=' + datas[fid]['timeid'] + '&form_name=' + datas[fid]['form_name'] + data
  // 	request.get('/Api/Index/save_form' + from_datas, {
  // 		data: data,
  // 		failRollback: true,
  // 		success: function (res) {
  // 			app.showTextWarining(datas[fid]['result'] || '提交成功', function () {
  // 				that.setData({
  // 					block_model: datas
  // 				})
  // 			});
  // 		}
  // 	});

  // },
  /****************************** 自定义 end ********************************/
  hidetabbar() { //隐藏默认tab
    wx.hideTabBar({
      fail: function () {
        setTimeout(function () { // 做了个延时重试一次，作为保底。
          wx.hideTabBar()
        }, 500)
      }
    });
  },

  // 设置滚动条到顶部
  setScrollTop() {
    this.setData({
      scrollTop: 0
    })
  },

  // 跳转到推荐榜单列表
  toRecommendList(e) {
    console.log(e.currentTarget.dataset.type)
    wx.navigateTo({
      url: '/pages/cart/recommend_list/recommend_list?type=' + e.currentTarget.dataset.type,
    })
  },

  noOpen() {
    wx.showModal({
      title: '暂未开放',
      showCancel: false
    })
  },
});